﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LevenBlog.Core.Data;
using LevenBlog.Core.Entities;
using LevenBlog.Core.Cache;

namespace LevenBlog.Core.Service
{
    public static class State
    {
        private static readonly string cacheName = "levenblog_servicecache_state";

        public static lb_state Get(IDbProvider provider)
        {
            lb_state find = ObjectCache.Get<lb_state>(cacheName);
            if (find == null) {
                find = ProviderManager.Factory.State.Get(provider);
                ObjectCache.Insert(cacheName, find);
            }
            return find;
        }

        public static void Update(IDbProvider provider, lb_state state)
        {
            ProviderManager.Factory.State.Update(provider, state);
            Remove();
        }

        public static void Remove()
        {
            ObjectCache.Remove(cacheName);
        }
    }
}
